// 获取月份英文
export const getChineseMouth = (m: number): string => {
    switch (m) {
        case 0:
            return "Jan.";
        case 1:
            return "Feb.";
        case 2:
            return "Mar.";
        case 3:
            return "Apr.";
        case 4:
            return "May.";
        case 5:
            return "Jun.";
        case 6:
            return "Jul.";
        case 7:
            return "Aug.";
        case 8:
            return "Sep.";
        case 9:
            return "Oct.";
        case 10:
            return "Nov.";
        case 11:
            return "Dec.";
        default:
            return "";
    }
}

// 获取日期模板
export const getMAndDObj = (date: Date): { y: string, m: string, d: string } => {
    const y = date.getFullYear()
    const m = date.getMonth()
    const d = date.getDate()

    return {
        y: y + '',
        m: m >= 10 ? '' + m : '0' + m,
        d: d >= 10 ? '' + d : '0' + d
    }
}

// 获取日期
export const getDate = (dateStr: string) => {

    if (Number(dateStr) === 0) {
        const date = getMAndDObj(new Date());
        dateStr = date.y + '-' + date.m + '-' + date.d;
    }

    const y = dateStr.substring(0, 4)
    const m = dateStr.substring(5, 7)
    const d = dateStr.substring(8)

    return new Date(`${y}-${m}-${d}`)
}

// 获取前一天日期
export const getPrevDate = (dateStr: string,num:number) => {
    const date = getDate(dateStr)
    date.setDate(date.getDate() - num)

    const y = date.getFullYear()
    let m: string | number = date.getMonth() + 1
    let d: string | number = date.getDate()

    m = m >= 10 ? m : '0' + m
    d = d >= 10 ? d : '0' + d

    return `${y}-${m}-${d}`
}

// 日期
export const getDateStr = (dateStr: string) => {
    const date = getDate(dateStr)
    const { m, d } = getMAndDObj(date)
    return `${m}月${d}日`
}


// 获取前一月日期
export const getPrevMonthDate = (dateStr: string) => {
    const date = getDate(dateStr)
    date.setMonth(date.getMonth() - 1)

    const y = date.getFullYear()

    let m: string | number = date.getMonth() + 1
    let d: string | number = date.getDate()

    m = m >= 10 ? m : '0' + m
    d = d >= 10 ? d : '0' + d

    return `${y}-${m}-${d}`
}

// 获取现在时间
export const  getNowDate = () => {
    const date = new Date()
    const y = date.getFullYear()

    let m: string | number = date.getMonth() + 1
    let d: string | number = date.getDate()

    m = m >= 10 ? m : '0' + m
    d = d >= 10 ? d : '0' + d

    return `${y}-${m}-${d}`
}